﻿/*-------------所有页面都会用到的一些公共js------------*/

//配置地图参数用于初始化
var OnloadCenterLng = 113.66695332324;
var OnloadCenterLat = 34.76204004795;
var iCenter			= 'iCenter';
var OnloadZoom		= 12;
	
//页面加载完自适应全屏
$(function(){
	autoFrame();//自动根据浏览器大小构建折叠窗口
});

//改变窗口大小自适应全屏
$(window).resize(function(){
	resize();
	autoFrame();
});

//左边头部当前位置鼠标滑过“更换区域”
function divSwitch(display){
	var guide=document.getElementById("menuguide");
	var pmenu=document.getElementById("pmenu");
	display?document.getElementById('pmenu').style.display = 'block':document.getElementById('pmenu').style.display = 'none';
}

//菜单的显示操作
function showDL(id){
	//结束实时轨迹的 setTimeout
	if(typeof(RealTimeSetTimeout) != 'undefined'){
		clearTimeout(RealTimeSetTimeout);
	}
	if(id !== 'ManageInfo'){
		//点击菜单以后初始化地图
		if(mapObj && !document.getElementById('right_iframe')){//如果地图存在，先销毁再创建
			mapObj.destroy();
		}
		$('#iCenter').html('');
		$('#div_float').remove();
		mapInit(); //创建地图
	}

	//点击以后隐藏所有的二级菜单
	$('.nodeUL dl').hide(500);
	$('.nodeUL li').css('border-bottom','1px solid #15589a');
	$('.nodeUL li span').css({'background':'url("images/icon_1.gif") no-repeat scroll 10px 8px #ffffff','color':'#666'});
	//判断二级菜单的闭合
	if($('#'+id+' dl').attr("class") == 'open'){
		$('#'+id+' dl').removeClass('open');
		return false;
	}
	$('.nodeUL dl').removeClass('open');
	//显示当前点击的菜单下的二级菜单
	$('#'+id+' dl').show(500);
	$('#'+id+' dl').addClass('open');
	$('#'+id).css('border-bottom','0px');
	$('#'+id+' span').css({'background':'url("images/icon_2.jpg") no-repeat scroll 10px 8px #A5A5A5','color':'#fff'});
	//根据id引入不同js
	getScript(id);
}

//页面自适应调整全屏
function autoFrame(){
	var width = document.body.clientWidth;//获取窗口宽度
	var height = pageHeight();//获取窗口高度
	var leftWidth = 225;
	var videoright=192;
	$("#main-left-div").css("width",leftWidth+"px").css('height',(height-95)+"px");
	$(".nodeList").css("width",(leftWidth-2)+"px").css('height',(height-118)+"px");
	$(".right").css("width",(width-leftWidth-20)+"px").css('height',(height-97)+"px");
	$(".main").css('height',(height-97)+"px");
	$("#right_iframe").css("width",(width-leftWidth-20)+"px").css('height',(height-97)+"px");
}

//获取页面高度
function pageHeight(){//返回页面高度
    if($.browser.msie){
        return document.compatMode == "CSS1Compat"? document.documentElement.clientHeight :
        document.body.clientHeight;
    }else{
        return self.innerHeight;
    }
};

//解决窗口resize之后仍然全屏
var reSizeCount=0;
function resize(){
	var tt = window.navigator.userAgent;
	if(tt.indexOf("Chorm")>-1){//chorm
		if(reSizeCount%2==0){autoFrame();}
	}else if(tt.indexOf("Firefox")>-1){//firefox
		autoFrame();
	}else if(tt.indexOf("MISE 8.0")>-1){//IE
		if(reSizeCount%3==0){autoFrame();}
	}else{autoFrame();}
	reSizeCount++;
}

//点击菜单地图上弹出的操作层
function showMapMenu(title,myStr){//根据内容定制menu，并显示menu在地图上
	$("#div_float").hide(500);
	$("#div_float").remove();
	$(document.body).append('<div id="div_float" style="display:none"></div>');
	var div_temp ="<div class='div_float_head'>&nbsp;<font color='white'>"+title+"</font><img src='images/ico_close.jpg' alt='关闭' /></div><div class='div_float_content'>"+myStr+"</div>";	
	$("#div_float").html(div_temp);
	$("#div_float div[class=div_float_head]").find("img").click(function(){
		$("#div_float").hide();
	});
	$(".div_float_content").css({opacity:0.9}); 
	$("#div_float").show(500);
	var height = $("#div_float").height();
	
	if(height > 400){//矫正高度，防止过高
		$(".div_float_content").css('height','400px');
		$(".div_float_content").css('overflow','auto');
		$(".div_float_content").css('overflow-x','hidden');
	}else{
		$(".div_float_contentt").css('overflow','');
		$(".div_float_content").css('height','');
	}
}

//根据菜单ID引入不同js文件
function getScript(id){
	var s = document.getElementById("itemList");
	if(s!=null){
		document.getElementsByTagName("head")[0].removeChild(s);
	}
	var url = 'public/'+id+'/itemList.js';
	s = document.createElement("script");
	s.id = "itemList";
	s.type = "text/javascript";
	s.src = url;
	var head = document.getElementsByTagName("head")[0]; //获取head结点，并将<script>插入到其中  
	head.appendChild(s);
}

//弹出层
function POPdiv(divName){
	//锁定body的层
	var bodyBack = document.createElement("div");
	bodyBack.setAttribute("id","bodybg")
	bodyBack.style.position = "absolute";
	bodyBack.style.width = "100%";
	bodyBack.style.height = "100%";
	bodyBack.style.zIndex = 999;
	bodyBack.style.top = 0;
	bodyBack.style.left = 0;
	bodyBack.style.filter = "alpha(opacity=50)";
	bodyBack.style.opacity = 0.5;
	bodyBack.style.background = "#ccc";
	document.body.appendChild(bodyBack)
	//显示内容的层
	document.getElementById(divName).style.display = 'block'
}

//关闭弹出层
function ClosePOPdiv(divName){
	document.body.removeChild(document.getElementById('bodybg'));
	document.getElementById(divName).style.display = 'none';
}